package org.br.erp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.br.erp.base.entity.Scmfilter;
import org.br.erp.base.entity.Scmfilteritem;
import org.br.erp.base.mapper.ScmfilterMapper;
import org.br.erp.base.mapper.ScmfilteritemMapper;
import org.br.erp.base.service.IScmfilteritemService;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 单据过滤表体
 * @Author: jeecg-boot
 * @Date:   2023-08-12
 * @Version: V1.0
 */
@Service
public class ScmfilteritemServiceImpl extends ServiceImpl<ScmfilteritemMapper, Scmfilteritem> implements IScmfilteritemService {
	
	@Autowired
	private ScmfilteritemMapper scmfilteritemMapper;

	@Autowired
	private ScmfilterMapper scmfilterMapper;
	
	@Override
	public List<Scmfilteritem> selectByMainId(String mainId) {
		QueryWrapper<Scmfilter> queryWrapper=new QueryWrapper<>();
//		queryWrapper.eq("id",mainId).or(item->item.eq("fiterdj",mainId));
//		List<Scmfilter> scmfilters = scmfilterMapper.selectList(queryWrapper);
//		if(scmfilters.size()==0){
//			return null;
//		}
//		QueryWrapper<Scmfilteritem> scmfilteritemQueryWrapper =  new QueryWrapper<>();
//		scmfilteritemQueryWrapper.eq("parentid",scmfilters.get(0).getId());
//		scmfilteritemQueryWrapper.eq("isvisable","Y");
//		scmfilteritemQueryWrapper.orderByAsc ("ordernum");
//		return scmfilteritemMapper.selectList(scmfilteritemQueryWrapper);
	return scmfilteritemMapper.selectByMainId(mainId);
	}

	@Override
	public List<Scmfilteritem> selectByFilterCode(String filterCode) {
		QueryWrapper<Scmfilter> queryWrapper=new QueryWrapper<>();
		queryWrapper.eq("fiterdj",filterCode);
		List<Scmfilter> scmfilters = scmfilterMapper.selectList(queryWrapper);
		if(scmfilters.size()==0){
			return null;
		}
		QueryWrapper<Scmfilteritem> scmfilteritemQueryWrapper=new QueryWrapper<>();
		scmfilteritemQueryWrapper.eq("parentid",scmfilters.get(0).getId());
		scmfilteritemQueryWrapper.eq("isvisable","Y");
		scmfilteritemQueryWrapper.orderByAsc("ordernum");
		return scmfilteritemMapper.selectList(scmfilteritemQueryWrapper);

	}
}
